#include "tca9548a.h"

#define TCA9548A_CHANNEL_0          0x01
#define TCA9548A_CHANNEL_1          0x02
#define TCA9548A_CHANNEL_2          0x04
#define TCA9548A_CHANNEL_3          0x08
#define TCA9548A_CHANNEL_4          0x10
#define TCA9548A_CHANNEL_5          0x20
#define TCA9548A_CHANNEL_6          0x40
#define TCA9548A_CHANNEL_7          0x80

void tca9548a_init(void)
{
    tca9548a_i2c_init();
}

void tca9548a_set_channel(uint8_t channel)
{
    uint8_t data;
    switch (channel)
    {
    case 0:
        data = TCA9548A_CHANNEL_0;
        break;
    case 1:
        data = TCA9548A_CHANNEL_1;
        break;
    case 2:
        data = TCA9548A_CHANNEL_2;
        break;
    case 3:
        data = TCA9548A_CHANNEL_3;
        break;
    case 4:
        data = TCA9548A_CHANNEL_4;
        break;
    case 5:
        data = TCA9548A_CHANNEL_5;
        break;
    case 6:
        data = TCA9548A_CHANNEL_6;
        break;
    case 7:
        data = TCA9548A_CHANNEL_7;
        break;
    default:
        break;
    }
    tca9548a_i2c_master_transmit(&data, 1);
}

void tca9548a_set_channel_mask(uint8_t channel_mask)
{
    tca9548a_i2c_master_transmit(&channel_mask, 1);
}

uint8_t tca9548a_get_channel_mask(void)
{
    uint8_t channel_mask[1];
    tca9548a_i2c_master_receive(channel_mask, 1);
    return channel_mask[0];
}
